package com.xbongbong.saas.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.domain.entity.ext.ConditionsEntityExt;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.elasticsearch.pojo.XbbAggregatedPage;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.pojo.FieldAttrEntityForImport;
import com.xbongbong.paas.pojo.ProductFieldPojo;
import com.xbongbong.paas.field.UnitItemPoJo;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.ImportFormDataDTO;
import com.xbongbong.paas.pojo.dto.SaasFormSaveDTO;
import com.xbongbong.paas.pojo.imports.CellTitlePojo;
import com.xbongbong.paas.pojo.imports.RowGroupPojo;
import com.xbongbong.paas.pojo.vo.PaasFormDataEsListVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.applist.pojo.vo.ListAppVO;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.businessdata.pojo.dto.ProductListDataDTO;
import com.xbongbong.pro.detailtab.dto.DetailTabDataGetDTO;
import com.xbongbong.pro.detailtab.vo.ProductDetailVO;
import com.xbongbong.pro.form.pojo.dto.ChildProductDTO;
import com.xbongbong.pro.formdata.pojo.dto.SaasAnalysisDataDTO;
import com.xbongbong.pro.formdata.pojo.vo.FormDataVO;
import com.xbongbong.pro.listbatch.pojo.dto.AddLabelDTO;
import com.xbongbong.pro.product.pojo.ProductWithSupplierPojo;
import com.xbongbong.pro.product.pojo.ProductWithWarehousePojo;
import com.xbongbong.pro.product.pojo.StockNotifyPojo;
import com.xbongbong.pro.product.pojo.dto.FormatRelativeProductDTO;
import com.xbongbong.pro.product.pojo.dto.ProductDeleteBatchDTO;
import com.xbongbong.pro.product.pojo.dto.ProductEditAttrUpdateDTO;
import com.xbongbong.pro.product.pojo.dto.ProductListDTO;
import com.xbongbong.pro.product.pojo.dto.ProductSearchDTO;
import com.xbongbong.pro.product.pojo.dto.ProductSerialDTO;
import com.xbongbong.pro.product.pojo.dto.ProductStockVerifyDTO;
import com.xbongbong.pro.product.pojo.dto.ProductUpdateBatchDTO;
import com.xbongbong.pro.product.pojo.vo.ChildProductVO;
import com.xbongbong.pro.product.pojo.vo.ProductDeleteBatchVO;
import com.xbongbong.pro.product.pojo.vo.ProductListVO;
import com.xbongbong.pro.product.pojo.vo.ProductSearchDetailVO;
import com.xbongbong.pro.product.pojo.vo.ProductSearchVO;
import com.xbongbong.pro.product.pojo.vo.ProductSerialVO;
import com.xbongbong.pro.product.pojo.vo.ProductUpdateBatchVO;
import com.xbongbong.saas.domain.entity.ProductStockUpdateEntity;
import com.xbongbong.saas.domain.entity.SpecificationEntity;
import com.xbongbong.saas.domain.entity.ext.ProductEntityExt;
import com.xbongbong.saas.enums.CompanyConfigEnum;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 产品
 * @author Jian.Wang
 * @date 2019/1/23 20:27
 * @since v1.0
 * @version v1.0
 */
public interface ProductService extends SaasSaveService {

    /**
     * 编辑时格式化解释
     *
     * @param formatExplainDTO 入参
     * @throws XbbException 异常
     * @author long.rao
     * @date 2019-06-22 17:35
     */
    void formatSpecialUpdateExplain(FormatExplainDTO formatExplainDTO) throws XbbException;

    /**
     * 详情格式化数据格式
     *
     * @param saasAnalysisDataDTO saas编辑数据
     * @throws XbbException 参数格式错误异常
     * @param result 要返回的jsonobject
     * @author 吴峰
     * @date 2019/6/6 13:55
     * @since v1.0
     **/
    void getFormatData(SaasAnalysisDataDTO saasAnalysisDataDTO, JSONObject result) throws XbbException;

    /**
     * 新建时格式化解释
     *
     * @param formatExplainDTO 入参
     * @throws XbbException 异常
     * @author long.rao
     * @date 2019-02-13 20:53
     */
    void formatAddExplain(FormatExplainDTO formatExplainDTO) throws XbbException;

    /**
     * 获取子产品的价格或成本区间
     *
     * @param childProductList 子产品列表数据
     * @param attr 属性名称
     * @param accuracy 小数精度
     * @throws XbbException 异常
     * @author long.rao
     * @date 2019-02-13 20:53
     */
    String getPriceOrCostRegion(List<PaasFormDataEntityExt> childProductList, String attr, Integer accuracy) throws XbbException;

    void handleMultiPrice(Map<Long, Object> multiProductsMap, List<PaasFormDataEntityExt> multiProductList, String corpid, Long productId,int priceAccuracy) throws XbbException;


        /**
         * 新建时将仓库信息加入到解释中
         *
         * @param formatExplainDTO 入参
         * @throws XbbException 异常
         * @author Jian.Wang
         * @date 2019-02-18 20:24
         */
     void formatAddWarehouseToExplain(FormatExplainDTO formatExplainDTO) throws XbbException;


    /**
     * 批量删除产品
     * @author 吴峰
     * @date 2019/2/26 15:13
     * @param productDeleteBatchDTO 前端传入对象
     * @return com.xbongbong.pro.product.pojo.vo.ProductDeleteBatchVO
     * @throws XbbException
    */
    ProductDeleteBatchVO deleteBatch(ProductDeleteBatchDTO productDeleteBatchDTO) throws XbbException;

    /**
     * 获取产品列表
     * @author 吴峰
     * @date 2019/3/2 11:11
     * @param productListDTO
     * @return com.xbongbong.pro.product.pojo.vo.ProductListVO
     * @throws XbbException 业务异常
     */
    ProductListVO findProductList(ProductListDTO productListDTO) throws XbbException;

    /**
     * 批量更新产品
     * @author 吴峰
     * @date 2019/3/2 11:42
     * @param productUpdateBatchDTO
     * @return com.xbongbong.pro.product.pojo.vo.ProductUpdateBatchVO
     * @throws XbbException 业务异常
     */
    ProductUpdateBatchVO updateBatch(ProductUpdateBatchDTO productUpdateBatchDTO)throws XbbException;




    /**
     * 获取原父产品下的子产品，从es获取
     *
     * @param childProductDTO
     * @author chaoxiong.lei
     * @Date 21:29 2019/2/14
     * @since v1.0
     **/
    PaasFormDataEsListVO getChildProductList(ChildProductDTO childProductDTO) throws XbbException;

    /**
     * 产品详情格式化产品返回给前端
     *
     * @param product 父产品实体
     * @param corpid 公司id
     * @author chaoxiong.lei
     * @Date 21:29 2019/2/14
     * @since v1.0
     **/
    ProductDetailVO getFormatExplainJsonArray(DetailTabDataGetDTO detailTabDataGetDTO, ProductEntityExt product, String corpid) throws XbbException;


    /**
     * 批量编辑某个字段
     * @author 吴峰
     * @date 2019/3/19 9:16
     * @param productEditAttrUpdateDTO
     * @return void
     * @throws XbbException 业务异常
     */
    void batchEditAttr(ProductEditAttrUpdateDTO productEditAttrUpdateDTO) throws XbbException;

    /**
     * 统一格式化单据关联产品
     *
     * @param formatRelativeProductDTO
     * @author chaoxiong.lei
     * @date 16:28 2019/3/22
     * @since v1.0
     * @return 前端可以回显的单条产品
     **/
    JSONObject getFormatProductJsonArray(FormatRelativeProductDTO formatRelativeProductDTO) throws XbbException;

    /**
     * 产品查询
     *
     * @param productSearchDTO 产品查询入参
     * @return ProductSearchVO
     * @author 徐俊杰
     * @date 2019/4/9 10:37
     * @since v1.0
     */
    ProductSearchVO productSearch(ProductSearchDTO productSearchDTO) throws XbbException;

    /**
     * 将Excel数据格式化成表单保存需要的JSON格式的数据
     *
     * @param importFormDataDTO 导入入参
     * @param titlePojoList     标题
     * @param rowGroupPojo      一个表单对应的一组Excel填写的数据
     * @param fieldAttrList     解释
     * @return FormDataAddDTO
     * @throws XbbException XbbException
     * @author lee
     * @date 2019/4/29 14:16
     * @since V1.0
     */
    FormDataAddDTO formatExcelValue(ImportFormDataDTO importFormDataDTO, List<CellTitlePojo> titlePojoList, RowGroupPojo rowGroupPojo, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;
    /**
     * 规格字段格式转换
     *
     * @param data 前端传回的data数据
     * @throws XbbException 参数格式错误异常
     * @author chaoxiong.lei
     * @date 15:38 2019/1/21
     * @since v1.0
     **/
    void formatParentProduct4Save(JSONObject data,String corpid, ProductEntityExt productEntityExt) throws XbbException;
    /**
     * 创建供应商关联关系 产品关联供应商
     *
     * @param productWithSupplierPojo 产品实体
     * @author GuoJun.HU
     * @since 3.14
     * 创建时间 2017/11/13 16:53
     */
    void associateWithSupplier(ProductWithSupplierPojo productWithSupplierPojo) throws XbbException;
    /**
     * 保存子规格产品
     *
     * @param paasFormDataEntity 数据实体
     * @param isJxcUse           是否启用进销存
     * @param isInsert           是否是新建
     * @throws XbbException 参数格式错误异常
     * @author chaoxiong.lei
     * @date 15:38 2019/1/21
     * @since v1.0
     **/
    ChildProductVO saveChildProduct(PaasFormDataEntity paasFormDataEntity, Boolean isJxcUse, Boolean isInsert, Integer costAccuracy) throws XbbException;

    /**
     * 子产品多规格渲染
     * @param paasFormDataESList
     * @param corpid
     */
    void setChildSpecification(List<PaasFormDataEntityExt> paasFormDataESList, String corpid);

    /**
     * 规格解析
     * @param isSpec
     * @param specStr
     * @param specificationLiist
     * @return
     */
    String decodeSpec(String isSpec, String specStr, List<SpecificationEntity> specificationLiist) ;

    /**
     * 子产品多规格渲染
     * @param paasFormDataESList
     * @param corpid
     */
    void formatChildSpecification(List<PaasFormDataEntityExt> paasFormDataESList, String corpid);

    void formatChildSpecification4LinkData(List<FormDataVO> paasFormDataESList, String corpid);

    /**
     * 获取移动端待采购(待生产)中的合同
     *
     * @param formDataListDTO 列表查询DTO
     * @param paasFormDataEsListVO 列表查询回参
     * @throws XbbException
     * @author long.rao
     * @date 2019-05-31 15:30
     */
    ListAppVO formatWaitProduct(FormDataListDTO formDataListDTO, PaasFormDataEsListVO paasFormDataEsListVO) throws XbbException;
    
    /**
     * @Author: wujian
     * @Description: 获取移动端待采购产品视图列表数据
     * @Date: 下午7:42 2022/2/16
     * @Param: [formDataListDTO, paasFormDataEsListVO]
     * @return: com.xbongbong.pro.applist.pojo.vo.ListAppVO
     **/
    ListAppVO formatWaitPurchaseProduct(FormDataListDTO formDataListDTO, PaasFormDataEsListVO paasFormDataEsListVO) throws XbbException;
    

    /**
     * 格式化导出值
     *
     * @param paasFormDataESList 数据
     * @throws XbbException 异常
     */
    void formatExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;


    /**
     * 根据productIdIn获取对应产品信息,需要分页信息，从es中获取
     * @param productIds
     * @param corpid
     * @param delEnum
     * @return
     * @throws XbbException
     */
    List<PaasFormDataEntityExt> getProductListById(Set<Long> productIds, String corpid, DelEnum delEnum) throws XbbException;

    Map<Long,PaasFormDataEntityExt> getProductMapByIdIn(Set<Long> productIds, String corpid, DelEnum delEnum) throws XbbException;

    /**
     * 库存查询导出
     * @param paasFormDataESList
     * @param formDataListDTO
     * @param fieldAttrList
     */
    void formatStockSearchExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO, List<FieldAttrEntityForImport> fieldAttrList);

    /**
     * 预警查询导出
     * @param paasFormDataESList
     * @param formDataListDTO
     * @param fieldAttrList
     */
    void formatWarningSearchExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO, List<FieldAttrEntityForImport> fieldAttrList);

    /**
     * 保质期查询导出
     * @param paasFormDataESList
     * @param formDataListDTO
     * @param fieldAttrList
     */
    void formatGuaranteeSearchExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException;

    /**
     * 待入库产品维度导出
     * @param paasFormDataESList
     * @param formDataListDTO
     */
    void formatWaitInstockProductExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO)throws XbbException;


    /**
     * 以销订购产品维度导出
     * @param paasFormDataESList
     * @param formDataListDTO
     */
    void formatWaitPurchaseProductExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO)throws XbbException;

    //智能补货导出
    void formatSmartReplenishmentExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO) throws XbbException;
    /**
     * 获取成本实现摘要、标签、标题
     * @param childProductESList 子产品
     * @param corpid 公司id
     * @param formDataId 父产品id
     * @return
     * @throws XbbException
     */
    Object getCostBySummary(List<PaasFormDataEntityExt> childProductESList, String corpid, Long formDataId) throws XbbException;

    /**
     * 根据父产品查询子产品
     * @param corpid
     * @param formDataId
     * @return
     * @throws XbbException
     */
    List<PaasFormDataEntityExt> getDataByParentId(String corpid, Long formDataId) throws XbbException;

    /**
     * Description: 获取单价实现摘要、标签、标题
     * @param childProductESList
     * @param corpid
     * @param formDataId
     * @throws XbbException
     * @author 刘阳
     * @date 2019/8/5 4:05 PM
     * @since v1.0
     */
    Object getPriceBySummary(List<PaasFormDataEntityExt> childProductESList, String corpid, Long formDataId) throws XbbException;

    Set<Long> associateWithWarehouse(ProductWithWarehousePojo productWithWarehousePojo) throws XbbException;

    Map<Long,JSONObject> setProductConditionsSuper(ProductListDataDTO productListDataDTO, List<ConditionsEntityExt> conditionsEntityExtList, ProductFieldPojo stockField) throws XbbException;


    /**
     * 根据产品idSet获取产品实体列表
     *
     * @param productIdSet 产品idSet
     * @param corpid       公司id
     * @param nameOrNoLike 名称或编号模糊搜索
     * @param page         页数
     * @param pageSize     每页个数
     * @param platForm     平台
     * @return org.springframework.data.elasticsearch.core.aggregation.AggregatedPage<com.xbongbong.paas.domain.entity.PaasFormDataEntity>
     * @throws XbbException findByPage会出现异常
     * @author 徐俊杰
     * @date 2019/8/29 19:49
     * @since v1.0
     */
    XbbAggregatedPage<PaasFormDataEntity> productEntityByProductId(Set<Long> productIdSet, String corpid, String nameOrNoLike,
                                                                   Integer page, Integer pageSize, String platForm) throws XbbException;

    /**
     * 封装产品搜索结果
     *
     * @param productList 产品列表
     * @return java.util.List<com.xbongbong.pro.product.pojo.vo.ProductSearchDetailVO>
     * @author 徐俊杰
     * @date 2019/8/30 9:38
     * @since v1.0
     */
    List<ProductSearchDetailVO> productSearchFormat(List<PaasFormDataEntity> productList);

    void setProductSupplierAndWarehouse(PaasFormDataEsListVO formDataListVO, String corpid, List<Long> dataIdList, boolean isSpuList) throws XbbException;

    void setProductSupplier(PaasFormDataEsListVO formDataListVO, String corpid, List<Long> dataIdList) throws XbbException;

    List<StockNotifyPojo> getSaveParam(JSONObject dataList, Map<Long, String> supplierNameMap, Map<Long, String> warehouseNameMap) throws XbbException;

    void updateProductStock(Map<Long, ProductStockUpdateEntity> productAddMap, String corpid) throws XbbException;

    boolean hasBatchOrSeqProduct(CompanyConfigEnum companyConfigEnum, String corpid) throws XbbException;

    /**
     * 序列号查重
     *
     * @param productSerialDTO 入参
     * @return XbbException
     */
    ProductSerialVO repeat(ProductSerialDTO productSerialDTO) throws XbbException;

    ProductSearchVO checkStock(ProductStockVerifyDTO productStockVerifyDTO) throws XbbException;

    void formatBatchExplain(List<FieldAttrEntity> fieldAttrEntityList, String enable);

    void formatSeqExplain(List<FieldAttrEntity> fieldAttrEntityList, String enable);

    void dataConsistencyUpdateSupplier(String corpid, Long dataId, String name) throws XbbException;

    JSONArray formatMultiPrice(List<UnitItemPoJo> unitItemPoJos, JSONArray price);

    /**
     * 标签的批量增删
     * @param addLabelDTO
     * @param addBatchList
     * @throws XbbException
     */
    void updateBatchLabelAttr(AddLabelDTO addLabelDTO, List<PaasFormDataEntityExt> addBatchList, Boolean addOrDelete) throws XbbException;


    /**
     * 通过id列表获取产品
     *
     * @param corpid        公司id
     * @param productIdIn   产品id列表
     * @param del           删除标志
     * @author Jian.Wang
     * @date  2018/2/21 17:26
     */
    List<PaasFormDataEntityExt> getProductListByIds(String corpid, List<Long> productIdIn, Integer del, List<String> fieldList) throws XbbException;

    void afterSaveForWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    void afterSaveForUpdateWorkflow(SaasFormSaveDTO saasFormSaveDTO) throws XbbException;

    void updateProductCostByid(List<ProductEntityExt> productEntityExtList, String corpid) throws XbbException;
    /**
     * 待出库产品维度导出
     * @param paasFormDataESList
     * @param formDataListDTO
     */
    void formatWaitOutstockProductExportValue(List<PaasFormDataEntityExt> paasFormDataESList, FormDataListDTO formDataListDTO);
}
